package nicepc.controller;

import nicepc.mapper.UserMapper;
import nicepc.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 01
 */
@RestController
@Service
public class UserController {

    @Autowired
    private UserMapper userMapper;

   /* @GetMapping("/selectUserList")
    public Map<String, Object> selectUserList(){

        return userMapper.selectids( "user1","1,2","name");
    }*/

    @GetMapping("/selectUserList")
    public  List<User> selectUserList1(){
        List<User> users = userMapper.selectUserList("user1");

        return users;
    }

//    @GetMapping("/insert")
//    public boolean insert(){
//        User user = new User("name", "testpwd");
//        if (userMapper.addUser("name,pwd","user1",user.getField())>0){
//            return true;
//        }
//        return false;
//    }

    @GetMapping("/insert")
    public boolean insert(){
        User user = new User("name1", "testpwd1","user1");
        if (userMapper.addUser(user)>0){
            return true;
        }
        return false;
    }

    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping("/redisTest")
    public String redisTest(){
        ValueOperations ops = redisTemplate.opsForValue();
        return (String) ops.get("s");
    }

    @GetMapping("/redisTest1")
    public String receive(){
        ValueOperations ops = redisTemplate.opsForValue();
        return (String) ops.get("receive");
    }
}
